<template>
  <ex-dialog
    width="800px"
    class="ex-diolog"
    :title="title"
    :visible="visible"
    @closeDialog="handleClose"
  >	
		<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="0" class="demo-ruleForm">
      <el-form-item label="" prop="remark">
				<el-input
          type="textarea"
          :autosize="{ minRows: 5}"
          placeholder="请输入拒绝原因"
          v-model.trim="ruleForm.remark">
        </el-input>
			</el-form-item>
    
			<el-form-item>
				<el-button @click="handleClose('ruleForm')">取消</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')" :loading="loading">拒绝</el-button>
			</el-form-item>
		</el-form>
  </ex-dialog>
</template>
<script>
// components
import Loading from '@/components/Loading/index'
// api
import {
  auditMerchant
} from "@/api/merchants/merchantsAudit"; 
import { string } from 'jszip/lib/support';

export default {
  components: {
    Loading
  },
  props: {
    visible: Boolean,
    id: String,
  },
  data() {
    var checkRemark = (rule, value, callback) => {
        if (value == '') {
          return callback(new Error('请输入拒绝原因'));
        } else {
          callback();
        }
      };
   
    return {
      title: '拒绝原因',
      loading: false,
      isNext: false,
			ruleForm: {
        remark: '',//拒绝原因
			},
			rules: {
          remark: [
            { required: true,validator: checkRemark ,trigger: ['blur','change'] }
          ],
         
      }
    }
  },
  computed: {
   
  },
  created() {
    
	},
  methods: {
    //提交
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          let data = {
            id: this.id,
            status: 3,
            remark: this.ruleForm.remark,
          }
          auditMerchant(data).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              });
              this.$emit('success')
              this.handleClose()
              this.loading = false
            }
          }).catch(() => {
            this.loading = false
          })
          
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

		//取消
    handleClose() {
      this.$emit('update:visible', false)
			// this.$refs[formName].resetFields();
    },
		//确认
		handleConfirm(){
			this.$emit('success', '你好')
		},
    handleSuccess(msg) {
      if (msg === '已拒绝') {
        var type = 'error'
      } else {
        var type = 'success'
      }
      this.$message({
        message: msg,
        type: type,
        duration: 1500,
        onClose: () => {
          this.handleClose()
          this.$emit('success')
        }
      })
    },
  }
}
</script>
<style lang="scss" scoped>
.ex-diolog {
  ::v-deep .ex--dialog--footer {
    border: none !important;
		padding: 0 !important;
  }
	::v-deep .ex--dialog--main {
    padding: 10px 20px !important; 
  }
}
::v-deep .avatar-uploader2 .el-upload {
  width: 100% !important;
}

.avatar-uploader2 {
  width: 130px;
  height: 130px;
  text-align: center;
  line-height: 130px;
  background-color: #fbfdff;
  border: 1px dashed #c0ccda;
}

.banner_img {
  width: 130px;
  height: 130px;
}
.el-input{
  width: 300px;
}
</style>